# coding:utf-8
from django.db import models

# 使用mysqlclient
class Video(models.Model):
    movieId = models.IntegerField(max_length=10, null=False)
    title = models.CharField(max_length=400)
    genres = models.CharField(max_length=300, default='')

    def __str__(self):
        return 'movieId:{},title:{}'.format(self.movieId, self.title)


class Ratings(models.Model):
    userId = models.IntegerField(max_length=10, null=False)
    movieId = models.IntegerField(max_length=10)
    rating = models.FloatField(max_length=10)

    def __str__(self):
        return 'userId:{},movieId:{}'.format(self.userId, self.movieId)

    @classmethod
    def add(cls, userId, movieId, rating):
        return cls.objects.create(
            userId=userId,
            movieId=movieId,
            rating=rating
        )